import type { ExtIdTuple, ExtUUidTuple, VARCHAR255_PG, VARCHAR50_PG } from "~/db.pg";

import { Creatable } from "~/extend";
import { ENUM_USER, ExtOwner } from "./core.define";

/** 核心用户 */
export type User = ExtUUidTuple & {
  nickname: VARCHAR50_PG;
  avatar: VARCHAR255_PG;
  desc: VARCHAR50_PG;
  type: ENUM_USER;
} & {
  joinRefUserSubList?: RefUserSub[];
  justUserPassword?: UserPassword;
  justUserWeChat?: UserWeChat;
  justUserEmail?: UserEmail;

  /** 登录到期时间 */
  withTimeExpired?: number;
};

/** 辅助账户
 * @refOwnerUUid32 主账户
 * @refCreatorId 辅助账户
 */
export type RefUserSub = ExtIdTuple & ExtOwner & Creatable;

/** 用户密码 */
export type UserPassword = ExtIdTuple &
  ExtOwner & {
    accountNumber: VARCHAR50_PG;
    password: VARCHAR50_PG;
  };

/** 用户邮箱 */
export type UserEmail = ExtIdTuple &
  ExtOwner & {
    email: VARCHAR50_PG;
  };

/** 用户微信 */
export type UserWeChat = ExtIdTuple &
  ExtOwner & {
    unionId: VARCHAR50_PG;
    nickname: VARCHAR50_PG;
    avatar: VARCHAR255_PG;
  };
